package com.dqhl.community.util;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.CountDownTimer;
import android.widget.TextView;


/**
 * Created by cheng on 2016/8/30.
 * 注册时发送验证码的倒计时工具类
 */
public class TimeCountRegisterUtil extends CountDownTimer {

    private Activity mActivity;
    private TextView tv;

    public TimeCountRegisterUtil(Activity mActivity, long millisInFuture, long countDownInterval, TextView tv) {
        super(millisInFuture, countDownInterval);
        this.mActivity = mActivity;
        this.tv = tv;
    }

    @SuppressLint("NewApi")
    @Override
    public void onTick(long millisUntilFinished) {
        String strSeconds = "剩余" + millisUntilFinished / 1000 + "秒";
        //设置不能点击
        tv.setClickable(false);
        //设置倒计时时间
        tv.setText(strSeconds);
        //设置按钮为灰色，这时是不能点击的
    }

    @SuppressLint("NewApi")
    @Override
    public void onFinish() {
        tv.setText("获取验证码");
        tv.setClickable(true);
    }
}
